import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

// 1. import the riverpod_annotation package
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../data/fake_auth_repository.dart';
// 2. add a part file
part 'sign_in_controller.g.dart';

// 3. use the @riverpod annotation
@riverpod
class SignInController extends _$SignInController {
  @override
  FutureOr<void> build() {}

  Future<void> signInAnonymous() async {
    final authRepo = ref.read(authRepositoryProvider);
    state = const AsyncLoading();
    state = await AsyncValue.guard(authRepo.signInAnonymously);
  }
}
